import React from 'react';
import PropTypes from 'prop-types'
import './index.scss';

class CommentItem extends React.Component {
  constructor(props) {
    super(props);
    this.state = {

    }
  }
  // 过滤数据
  filter(data) {
    const reg1 = new RegExp('(<SCRIPT)[\\s\\S]*?((</SCRIPT>)|(/?>))', 'gi')
    const reg2 = new RegExp('<script>.*<\/script>', 'gi')
    return {
      // 发布时间
      date: data.date.substr(0, 10),
      // 作者Id
      author: data.author_name,
      content: data.content.rendered.replace(reg2, '').replace(reg1, ''),
    }
  }
  render() {
    const data = this.filter(this.props.data);
    return (
      <div className="comment-item">
        <div className="comment-top">
          <span className="comment-author">
            {data.author}
          </span>
          <span className="comment-time">
            {data.date}
          </span>
        </div>
        <div className="comment-content" dangerouslySetInnerHTML={{ __html: data.content }} />
      </div>
    )
  }
}
export default CommentItem;
CommentItem.propTypes = {
  data: PropTypes.objectOf(Object),
}
